//package org.linlinjava.litemall.db.service;
//
//import com.wechat.pay.java.core.Config;
//import com.wechat.pay.java.core.RSAAutoCertificateConfig;
//import com.wechat.pay.java.core.RSAPublicKeyConfig;
//import com.wechat.pay.java.core.notification.NotificationConfig;
//import com.wechat.pay.java.core.notification.RSAPublicKeyNotificationConfig;
//import com.wechat.pay.java.service.payments.jsapi.JsapiService;
//import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
//import com.wechat.pay.java.service.payments.jsapi.model.Amount;
//import com.wechat.pay.java.service.payments.jsapi.model.Payer;
//import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
//import com.wechat.pay.java.service.refund.RefundService;
//import com.wechat.pay.java.service.refund.model.Refund;
//import org.linlinjava.litemall.db.core.RedisCache;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.stereotype.Service;
//
//import java.math.BigDecimal;
//import java.util.Map;
//
//@Service
//public class WxService {
//
//    @Autowired
//    private RedisCache redisCache;
//
//    public static String privateKeyPath = "E:\\workSpace\\damaojia\\wxCert\\apiclient_key.pem";
//    public static String pubKeyPath = "E:\\workSpace\\damaojia\\wxCert\\pub_key.pem";
//    @Bean("jsapiServiceExtension")
//    public JsapiServiceExtension build() {
//        Map<String,String> configMap=redisCache.getCacheMap("sys_config");
////        Config config =
////                new RSAAutoCertificateConfig.Builder()
////                        .merchantId("1605620129")
////                        .privateKeyFromPath(privateKeyPath)
//////                        .privateKey(configMap.get("private_key_content"))
////                        .merchantSerialNumber("6412488207A36E56621A82B80A667322D1EE2111")
////
////                        .apiV3Key("JqVkXp1iYmRfAhw3eNzVlKjH8L9o5sQ2")
////                        .build();
//        Config config =
//                new RSAPublicKeyConfig.Builder()
//                        .merchantId(configMap.get("wx_mch-id")) //微信支付的商户号
////                        .privateKeyFromPath(privateKeyPath) // 商户API证书私钥的存放路径
//                        .privateKey(configMap.get("private_key_content")) // 商户API证书私钥的存放路径
//                        .publicKey(configMap.get("pub_key_content"))
////                        .publicKeyFromPath(pubKeyPath) //微信支付公钥的存放路径
//                        .publicKeyId(configMap.get("pub_key_id")) //微信支付公钥ID
//                        .merchantSerialNumber(configMap.get("merchant_serial_number")) //商户API证书序列号
//                        .apiV3Key(configMap.get("apiV3_key")) //APIv3密钥
//                        .build();
//        // 构建service
//        JsapiServiceExtension service = new JsapiServiceExtension
//                .Builder()
//                .config(config)
//                .signType("RSA")
//                .build();
//        return service;
//    }
//
//
//
//    @Bean
//    public NotificationConfig buildConfig() {
//        Map<String,String> configMap=redisCache.getCacheMap("sys_config");
//        NotificationConfig config = new RSAPublicKeyNotificationConfig.Builder()
//                .publicKey(configMap.get("pub_key_content"))
////                .publicKeyFromPath(publicKeyPath)
//                .publicKeyId(configMap.get("pub_key_id"))
//                .apiV3Key(configMap.get("apiV3_key"))
//                .build();
//        return config;
//    }
//
//
//    /**
//     * 构建微信支付请求
//     * @param openid 用户表示
//     * @param orderSn 订单号
//     * @param totalFee 总金额
//     * @return
//     */
//
//    public PrepayRequest buildPrepayRequest(String openid, String orderSn, BigDecimal totalFee,String attach) {
//        Map<String ,String> configMap=redisCache.getCacheMap("sys_config");
//        PrepayRequest prepayRequest = new PrepayRequest();
//        prepayRequest.setAppid(configMap.get("wx_sub-app-id"));
//        prepayRequest.setMchid(configMap.get("wx_sub-mch-id"));
//        prepayRequest.setDescription("test");
//        prepayRequest.setOutTradeNo(orderSn);
//        prepayRequest.setNotifyUrl(configMap.get("wx_notify-url"));
//        Amount amount = new Amount();
//        amount.setCurrency("CNY");
//        Integer amountTotal = totalFee.multiply(new BigDecimal(100)).intValue();
//        amount.setTotal(amountTotal);
//        prepayRequest.setAmount(amount);
//        Payer payer = new Payer();
//        payer.setOpenid(openid);
//        prepayRequest.setPayer(payer);
//        prepayRequest.setAttach(attach);
//        return prepayRequest;
//
//    }
//
//    public Refund buildRefundRequest(String outTradeNo, String outRefundNo, BigDecimal totalFee) {
//        Refund refund = new Refund();
//        refund.setOutTradeNo(outTradeNo);
//        refund.setOutRefundNo(outRefundNo);
//        com.wechat.pay.java.service.refund.model.Amount amount=new com.wechat.pay.java.service.refund.model.Amount();
//        amount.setRefund(totalFee.multiply(new BigDecimal(100)).longValue());
//        amount.setTotal(amount.getRefund());
//        amount.setCurrency("CNY");
//        refund.setAmount(amount);
//
//
//        return refund;
//    }
//
//    @Bean("refundService")
//    public RefundService buildRefundService() {
//        Map<String,String> configMap=redisCache.getCacheMap("sys_config");
//        Config config =
//                        .build();
